#!/bin/bash

filename="updated-or-added-files.txt"

echo "Creating tree structure..."

#
# Ensure the directory trees are there. This is to stop files being skipped
#
svn ls -R web | tr -d '\15\32' | grep -P '/$' | sort > directories.txt

while read line
	do svn update -q --depth empty web/${line}
done < directories.txt

#cat directories.txt

echo "Finding the set of modified files..."

#
# Find the list of all files modified between two checkouts and write to file
#  
svn log -v -q --incremental --revision $1:$2 web | grep -P -w -o '[MA] [\S]+' | sort | uniq > $filename

# echo "Done, written: to \"$filename\""

#
# print and check out each file
#
while read line
	do svn update -q --force ${line:9}
done < $filename

# Create a report

echo REPORT - $(date '+%Y-%m-%d,%H:%M')> report.txt
echo r$2 to r$1 >> report.txt
echo 			>> report.
echo FILES 		>> report.txt
echo 			>> report.txt
cat $filename 		>> report.txt

echo Report generated: report.txt

rm $filename
rm directories.txt